package com.rocket.demo3;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.*;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class Consumer3 {
    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer3 = new DefaultMQPushConsumer("consumer3");
        consumer3.setNamesrvAddr("192.168.126.137:9876");
        consumer3.subscribe("Topic3", "*");
        consumer3.registerMessageListener(new MessageListenerConcurrently(){
            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext ctx) {
                System.out.println("------------------------------");
                for (MessageExt msg : list) {
                    long t = System.currentTimeMillis() - msg.getBornTimestamp();
                    System.out.println(new String(msg.getBody()) + " - 延迟: "+t);
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });
        consumer3.start();
        System.out.println("开始消费数据");
    }
}
